home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 158 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: bmecg.bme.ohio-state.edu!xiaoyi
  2. From: xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu)
  3. Newsgroups: comp.lang.c
  4. Subject: qsort help
  5. Date: 3 Jan 1996 00:31:03 GMT
  6. Organization: Biomedical Engineering OSU
  7. Distribution: world
  8. Message-ID: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu>
  9. Reply-To: xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu)
  10. NNTP-Posting-Host: bmecg.bme.ohio-state.edu
  11. Keywords: qsort
  12.  
  13. Hi, I am having some problems with the qsort routine.
  14.  
  15.  
  16. int (*compar)(int *a, int *b)
  17. {
  18.   if (*a < *b) return -1;
  19.   else if (*a == *b) return 0;
  20.   else return 1;
  21. }
  22.  
  23. int return_moved_contour(int ix, int iy)
  24. {
  25.   int i, ac, count=0;
  26.   int y_coord[10]; /* stores y coordinates whose x == ix */
  27.  
  28.   for (ac=0; ac<areaindex; ac++)
  29.     {
  30.       for (i=0; i<index[ac]; i++)
  31.     {
  32.       if (xpos[ac][i] == ix) y_coord[count++] = ypos[ac][i];
  33.     }
  34.       if (count == 0) continue; /* not in this contour */
  35.       else {
  36.     qsort(y_coord, count, sizeof(int), compar);
  37.     i = 0;
  38.     while (i<count/2) {
  39.       if ((y_coord[i] <= iy) && (y_coord[i+1] >= iy))
  40.         return ac;
  41.       else i+=2;
  42.     }
  43.       }
  44.     }
  45.   return -1; /* cursor not within a contour, no response will be generated */
  46. }
  47.  
  48. When I tried to compile, an error was generated: 
  49.     Error: try.c, line 791: compar must have function type
  50.  
  51. I doublechecked the man page of qsort but still can't figure out what's
  52. wrong.
  53.  
  54. Could someone give me a hand here?
  55.  
  56. Thanks.
  57.  
  58. Xiaoyi
  59.  
  60. /=======================================================================\
  61. | Xiaoyi Wu        || If you can't convince them, confuse them.         |
  62. | 614-421-0934 (h) ||  xiaoyi@mozart.bme.ohio-state.edu                 |
  63. | 614-292-1555 (o) ||  http://chopin.bme.ohio-state.edu/~xiaoyi/hi.html |
  64. \~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
  65.